<!-- 报告送审 -->
<template>
  <div>
    <card :bordered="false">
      <p slot="title">报告送审</p>
      <table id="reportTria" width='100%' border="1" cellspacing="0" cellpadding="0" ref="print">
        <tr>
          <th colspan="4">报告送审表</th>
        </tr>
        <tr>
          <td width="25%">项目编号</td>
          <td colspan="3">
            {{info.Project_number}}
          </td>
        </tr>
        <tr>
          <td>项目名称</td>
          <td colspan="3">
            <Input v-model="info.Project_name" />
          </td>
        </tr>
        <tr>
          <td>建设单位</td>
          <td colspan="3">
            <Input v-model="info.Build_unit" />
          </td>
        </tr>
        <tr>
          <td>建设地点</td>
          <td colspan="3">
            <Input v-model="info.Build_address" />
          </td>
        </tr>
        <tr>
          <td>报告类型</td>
          <td colspan="3">
            <Input v-model="info.Report_type" />
          </td>
        </tr>
        <tr>
          <td>项目负责人</td>
          <td width="25%">
            <Input v-model="info.Perject_leader" />
          </td>
          <td width="25%">项目组其他成员</td>
          <td>
            <Input v-model="cyz" />
          </td>
        </tr>
        <tr>
          <td>审批部门</td>
          <td>
            <Input v-model="info.Approval_unit" />
          </td>
          <td>送审时间</td>
          <td>
            {{this.$moment().format('YYYY-MM-DD')}}
          </td>
        </tr>
        <tr>
          <td>送审版报告</td>
          <td colspan="3">
            <Upload action="//jsonplaceholder.typicode.com/posts/">
              <Button>上传</Button>
            </Upload>
            <p>上传文件格式为docx、doc、PDF、WPS、图片、压缩文件</p>
          </td>
        </tr>
      </table>
      <Row type="flex" justify="space-between" class="topmargin">
        <Col span="12">
        <PrintButton v-if="flag" Url="print/printAudit" :Project_id="info.Id"></PrintButton>
        </Col>
        <Col span="12">
        <div style="float: right">
          <Button type="primary" @click="submit('save')">保存</Button>
          <Button type="primary" @click="submit('submit')">提交评估</Button>
        </div>
        </Col>
      </Row>
      <StepBar :status="5" />

    </card>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        flag: false,
        info: {},
        query: [],
        cyz: '',
      }
    },
    mounted() {
      let query = this.$route.query
      this.query = query
      this.getProject(this.query.id, this.query.Project_id)
      // 项目成员组
      this.findStaffs()
    },
    methods: {
      /* 获取当前创建项目 */
      getProject(id) {
        axios.get('/projectInformation/findProjectByID', {
          params: {
            id: id || this.$route.query.Project_id
          }
        }).then(res => {
          this.info = res.info
          localStorage.projectType = this.info.Perject_type
          this.flag = true
        }).catch(err => {
          alert('请求崩溃1231')
        })
      },
      findStaffs() {
        axios.get('/audit/findStaffs', {
          params: {
            Project_id: this.query.id
          }
        }).then(res => {
          console.log(res)
          if (res._STATUS == 1) {
            let cyz = []
            res.data.forEach((e, i) => {
              cyz.push(e['Staffs_name'])
            });
            this.cyz = cyz.join(',')
          }
        })
      },
      // 保存 save / 提交 submit
      submit(type) {
        let info = this.info
        info.btn_way = type == 'save' ? 1 : 2
        info.Perject_type = type == 'save' ? 11 : 11
        console.log(info)
        axios.post('/projectInformation/saveOrUpdateProject', info).then((res) => {
          if (res._STATUS == 1) {
            let title = res._MESSAGE
            if (type == 'save') {
              this.$Modal.success({
                title,
              })
            } else {
              this.$router.push({
                name: "technologyAssessment",
                query: {
                  id: this.$route.query.id || this.$route.query.Project_id
                }
              })
            }
          } else {
            // 提示
            this.$Modal.error({
              title,
            })
          }
        }).catch(err => {
          alert('炸了')
        })

      }
    }
  }
</script>

<style lang="less">
  #reportTria {
    .ivu-input {
      border: none !important;
      text-align: center;
      height: 30px;

      input {
        outline: medium;
      }
    }
  }
</style>